import middleware from '@/api/middleware'
import { getToken, setToken, removeToken } from '@/utils/auth'
import { resetRouter } from '@/router'


const getDefaultState = () => {
  return {

  }
}

const state = getDefaultState()

const mutations = {

}

const actions = {


  // get user info
  getAll({ commit, state }) {
    return new Promise((resolve, reject) => {
      middleware.getAll().then(response => {
        if (response && response.code == 'success')
          resolve(response.data)
        else reject(response.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // get user info
  get({ commit, state }, componentId) {
    return new Promise((resolve, reject) => {
      middleware.get(componentId).then(response => {
        if (response && response.code == 'success')
          resolve(response.data)
        else reject(response.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // get user info
  update({ commit, state }, data) {
    debugger
    return new Promise((resolve, reject) => {
      middleware.update(data).then(response => {
        if (response && response.code == 'success')
          resolve(response.data)
        else reject(response.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  create({ commit, state }, data) {
    debugger
    return new Promise((resolve, reject) => {
      middleware.create(data).then(response => {
        if (response && response.code == 'success')
          resolve(response.data)
        else reject(response.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  delete({ commit, state }, id) {
    return new Promise((resolve, reject) => {
      middleware.delete(id).then(response => {
        if (response && response.code == 'success')
          resolve(response.data)
        else reject(response.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  copy({ commit, state }, id) {
    return new Promise((resolve, reject) => {
      middleware.copy(id).then(response => {
        if (response && response.code == 'success')
          resolve(response.data)
        else reject(response.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  execute({ commit, state }, data) {
    return new Promise((resolve, reject) => {
      middleware.execute(data).then(response => {
        if (response && response.code == 'success')
          resolve(response.data)
        else reject(response.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

